package com.profgj.profgj.service.impl;

import com.profgj.profgj.entity.PublishPolicyFile;
import com.profgj.profgj.dao.PublishPolicyFileDao;
import com.profgj.profgj.service.PublishPolicyFileService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * (PublishPolicyFile)表服务实现类
 *
 * @author makejava
 * @since 2021-06-29 13:11:18
 */
@Service("publishPolicyFileService")
public class PublishPolicyFileServiceImpl implements PublishPolicyFileService {
    @Resource
    private PublishPolicyFileDao publishPolicyFileDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PublishPolicyFile queryById(Long id) {
        return this.publishPolicyFileDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<PublishPolicyFile> queryAllByLimit(int offset, int limit) {
        return this.publishPolicyFileDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param publishPolicyFile 实例对象
     * @return 实例对象
     */
    // 事务隔离级别2 事务传播当是否有事务都开启一个新的事务
    @Transactional(isolation = Isolation.READ_COMMITTED,propagation = Propagation.REQUIRES_NEW)    // 开启事务
    @Override
    public PublishPolicyFile insert(PublishPolicyFile publishPolicyFile) {
        this.publishPolicyFileDao.insert(publishPolicyFile);
        return publishPolicyFile;
    }

    /**
     * 修改数据
     *
     * @param publishPolicyFile 实例对象
     * @return 实例对象
     */
    // 事务隔离级别2 事务传播当是否有事务都开启一个新的事务
    @Transactional(isolation = Isolation.READ_COMMITTED,propagation = Propagation.REQUIRES_NEW)    // 开启事务
    @Override
    public PublishPolicyFile update(PublishPolicyFile publishPolicyFile) {
        this.publishPolicyFileDao.update(publishPolicyFile);
        return this.queryById(publishPolicyFile.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    // 事务隔离级别2 事务传播当是否有事务都开启一个新的事务
    @Transactional(isolation = Isolation.READ_COMMITTED,propagation = Propagation.REQUIRES_NEW)    // 开启事务
    @Override
    public boolean deleteById(Long id) {
        return this.publishPolicyFileDao.deleteById(id) > 0;
    }

    /**
     * 关键字搜索政策文件
     * @param search
     * @param start
     * @param length
     * @return
     */
    @Override
    public List<PublishPolicyFile> queryAllByLimitAndKeyword(String search, Integer start, Integer length){
        return this.publishPolicyFileDao.queryAllByLimitAndKeyword(search, start, length);
    }

    /**
     * 关键字搜索政策文件列表
     * @param search
     * @return
     */
    @Override
    public List<PublishPolicyFile> queryAllByKeyword(String search){
        return this.publishPolicyFileDao.queryAllByKeyword(search);
    }

    /**
     * 搜索政策文件列表
     * @return
     */
    @Override
    public List<PublishPolicyFile> queryAll(){
        return this.publishPolicyFileDao.queryAll2();
    }
}
